package com.wesh.user.controller;

import com.wesh.user.entity.UserInfo;
import com.wesh.user.entity.UserSystemMessage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserInfoController {

    @GetMapping("uInfo")
    public UserInfo userInfo(){
        UserInfo userInfo = new UserInfo();
        userInfo.setId(1);
        userInfo.setNickname("Yphen");
        userInfo.setUsername("蔡云春");
        userInfo.setAge(18);
        userInfo.setGender(1);
        return userInfo;
    }

    @GetMapping("uMessages")
    public List<UserSystemMessage> userMessageList(HttpServletRequest request){
        String authorization = request.getHeader("Authorization");
        System.out.println(authorization);
        String loginTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"));
        return Arrays.asList(new UserSystemMessage(1,1, String.format("您在%s进行了登录操作。", loginTime), new Date()),
                new UserSystemMessage(2,1,String.format("xxx在%s查看了您。", loginTime), new Date()));
    }

}
